﻿@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutDialog.cshtml";
   ViewBag.Title = "上传图片";
}
@section HeaderContent{
<script src="~/Scripts/webuploader/webuploader.min.js"></script>
<script src="~/Areas/admin/Scripts/uploader.js"></script>
<script>
   var api = top.dialog.get(window); //获取父窗体对象
   //页面加载完成执行
   $(function () {
      //设置按钮及事件
      api.button([{
         value: '确定',
         callback: function () {
            execPicHtml();
         },
         autofocus: true
      }, {
         value: '取消',
         callback: function () { return true; }
      }
      ]);
      //初始化上传控件
      $(".upload-img").InitUploader({ sendurl: "/tools/upload_ajax.ashx", swf: "/scripts/webuploader/uploader.swf" });
      //修改状态，赋值给表单
      if ($(api.data).length > 0) {
         var parentObj = $(api.data).parent().parent();
         $("#txtImgUrl").val(parentObj.find("input[name='item_imgurl']").val());
         $("#txtTitle").val(parentObj.find("input[name='item_title']").val());
         $("#txtContent").val(parentObj.find("input[name='item_content']").val());
         $("#txtLinkUrl").val(parentObj.find("input[name='item_linkurl']").val());
         $("#txtSortId").val(parentObj.find("input[name='item_sortid']").val());
      }
   });

   //创建选项节点
   function execPicHtml() {
      var currDocument = $(document); //当前文档
      if ($("#txtTitle").val() == "") {
         top.dialog({
            title: '提示',
            content: '图片文字不可为空！',
            okValue: '确定',
            ok: function () { },
            onclose: function () {
               $("#txtTitle", currDocument).focus();
            }
         }).showModal(api);
         return false;
      }
      if ($("#txtImgUrl").val() == "") {
         top.dialog({
            title: '提示',
            content: '图片路径不可为空！',
            okValue: '确定',
            ok: function () { },
            onclose: function () {
               $("#txtImgUrl", currDocument).focus();
            }
         }).showModal(api);
         return false;
      }
      if ($("#txtLinkUrl").val() == "") {
         top.dialog({
            title: '提示',
            content: '链接地址不可为空！',
            okValue: '确定',
            ok: function () { },
            onclose: function () {
               $("#txtLinkUrl", currDocument).focus();
            }
         }).showModal(api);
         return false;
      }
      if ($("#txtSortId").val() == "") {
         top.dialog({
            title: '提示',
            content: '图片排序不可为空！',
            okValue: '确定',
            ok: function () { },
            onclose: function () {
               $("#txtSortId", currDocument).focus();
            }
         }).showModal(api);
         return false;
      }
      //创建选项节点的HTML
      if ($(api.data).length > 0) {
         var parentObj = $(api.data).parent().parent();
         parentObj.find("input[name='item_sortid']").val($("#txtSortId").val());
         parentObj.find("input[name='item_title']").val($("#txtTitle").val());
         parentObj.find("input[name='item_imgurl']").val($("#txtImgUrl").val());
         parentObj.find("input[name='item_linkurl']").val($("#txtLinkUrl").val());
         parentObj.find("input[name='item_content']").val($("#txtContent").val());

         parentObj.find(".item_sortid").html($("#txtSortId").val());
         if ($("#txtImgUrl").val() == "") {
            parentObj.find(".item_imgurl").html("-");
         } else {
            parentObj.find(".item_imgurl").html('<img src="' + $("#txtImgUrl").val() + '" width="32" height="32" />');
         }
         parentObj.find(".item_title").html($("#txtTitle").val());
         parentObj.find(".item_linkurl").html($("#txtLinkUrl").val());

         api.close();
      } else {
         var liHtml = '<tr class="td_c">'
         + '<td><input type="hidden" name="item_id" value="0" />'
         + '<input type="hidden" name="item_content" value="' + $("#txtContent").val() + '" />'
         + '<input type="hidden" name="item_imgurl" value="' + $("#txtImgUrl").val() + '" />'
         + '<span class="item_imgurl img-box"><img src="' + $("#txtImgUrl").val() + '" /></span></td>'
         + '<td><input type="hidden" name="item_title" value="' + $("#txtTitle").val() + '" />'
         + '<span class="item_title">' + $("#txtTitle").val() + '</span></td>'
         + '<td><input type="hidden" name="item_linkurl" value="' + $("#txtLinkUrl").val() + '" />'
         + '<span class="item_linkurl">' + $("#txtLinkUrl").val() + '</span></td>'
         + '<td><input type="hidden" name="item_sortid" value="' + $("#txtSortId").val() + '" />'
         + '<span class="item_sortid">' + $("#txtSortId").val() + '</span></td>'
         + '<td><a title="编辑" class="img-btn" onclick="showImgDialog(this);"><i class="iconfont icon-edit"></i></a>'
         + '<a title="删除" class="img-btn" onclick="delItemTr(this);">删除</a><i class="iconfont icon-delete"></i></td>';
         api.close(liHtml).remove();
      }
      return false;
   }
</script>
}

<form id="form1"  method="post" action="#">
<div class="div-content">
  <dl>
    <dt>排序数字</dt>
    <dd><input type="text" id="txtSortId" value="99" class="input txt small" onkeydown="return checkNumber(event);" /></dd>
  </dl>
  <dl>
    <dt>标题文字</dt>
    <dd><input type="text" id="txtTitle" class="input txt" /></dd>
  </dl>
  <dl>
    <dt>上传图片</dt>
    <dd>
      <input type="text" id="txtImgUrl" class="input txt upload-path" />
      <div class="upload-box upload-img"></div>
    </dd>
  </dl>
  <dl>
    <dt>链接地址</dt>
    <dd><input type="text" id="txtLinkUrl" class="input txt" /></dd>
  </dl>
  <dl>
    <dt>图片描述</dt>
    <dd>
        <textarea id="txtContent" class="input"></textarea>
    </dd>
  </dl>
</div>
</form>